#include "rbTree.h"

//根节点及关键字，direction见print_rbtree
static void rbtree_print(RBTree tree,Type key,int direction)
{
    if(tree!=NULL)
    {
        
        if(0==direction)
        {
            //tree是根节点
            printf("%2d (B) is root\n",tree->key);
        }else{
            //tree是分支结点
            //当前结点的值、颜色、父节点的值、左孩子还是右孩子
            printf("%2d(%s) is %2d's %6s child\n",tree->key,rb_is_red(tree)?"R":"b",\
            key,direction==1?"right":"left");
        }
        //递归
        rbtree_print(tree->left,tree->key,-1);
        rbtree_print(tree->right,tree->key,1);
    }
}

//
void print_rbtree(RBRoot* root)
{
    if (root != NULL && root->node != NULL)
    {
        //当前结点、父节点的值（递归中看的更清楚）、
        //用来记录是否为根结点且可用来确认是左孩子还是右孩子（结合打印处更清晰）
        rbtree_print(root->node, root->node->key, 0);
    }
        
}